//
//  JourneySummaryView.swift
//  AirlineReservation
//
//  Created by Kevin on 2020/1/20.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit

class TripSummaryView: UIView {
    
    // 显示的标题文本
    private let titles = ["时长(小时)","飞行(次)","里程(千米)"]
    
    public var tripSummary:[String]? {
        didSet {
            for item in subviews {
                item.removeFromSuperview()
            }
            setNeedsLayout()
        }
    }
    
    override func layoutSubviews() {
        
        // 飞行次数、城市、时长
        let width = frame.width / 3
        for i in 0..<titles.count {
            let title = UILabel()
            title.text = titles[i]
            title.textAlignment = .center
            title.textColor = UIColor.gray
            title.font = UIFont.systemFont(ofSize: 11)
            title.frame = CGRect(x: CGFloat(i) * width, y: MARGIN25, width: width, height: MARGIN)
            addSubview(title)
            // 数据
            let text = UILabel()
            text.text = tripSummary?[i] ?? "0"
            text.textAlignment = .center
            text.textColor = UIColor.black
            text.frame = CGRect(x: CGFloat(i) * width, y:title.frame.maxY + 8, width: width, height: MARGIN)
            addSubview(text)
            
            // 两道竖线
            if i != 0 {
                let line = UIView()
                line.backgroundColor = UIColor.gray
                line.frame = CGRect(x: width * CGFloat(i), y:title.frame.maxY, width: 1, height: 25)
                addSubview(line)
            }
        }
    }
}
